//************************************************************************
// author	:	vera												
// date		:	2011/4/3 1:28 					                 
//************************************************************************
#ifndef SL_VIEW_H_
#define SL_VIEW_H_
#include "Config.h"
#include "Object.h"
#include "Camera.h"
#include "FrameStamp.h"
namespace sl
{
	// there are a master camera and other slaves
	class SL_EXPORT View : public sl::Object
	{
	public:

		// using for more camera and scene
		struct Slave
		{
			
			Slave();
			Slave( sl::Camera* pCamera,sl::Matrix4 mView, sl::Matrix4 mProject )
			{
				_rCamera	= pCamera;
				_mView.set( mView );
				_mProjection.set( mProject );
			}
			sl::ref_ptr<Camera>		_rCamera;
			sl::Matrix4				_mView;
			sl::Matrix4				_mProjection;

		};

	public:
		View(void);

		void setFrameStamp( sl::FrameStamp* frameStamp ){ m_rFrameStamp = frameStamp; };
		sl::FrameStamp * getFrameStamp(){ return m_rFrameStamp.get(); }
		
		void setViewport( u32 x, u32 y, u32 width, u32 height );
		sl::Viewport * getViewport(){ return m_rCamera->GetViewport(); }

		void setCamera( sl::Camera * camera );
		const sl::Camera * getCamera() const { return m_rCamera.get(); }

		void addSlave( sl::Camera * camera, sl::Matrix4 & view, sl::Matrix4 & project );

		void removeSlave( u32 iPos );

		u32 getNumSlave();

		Slave getSlave( u32 iPos );

		void setProjectMatrixAsProjective( double fov, double aspectRatio, double zNear, double zFar );

		void setViewMatrixAsLookAt( Vector3 & eye, Vector3 & center, Vector3 & up );

		void updateSlaves();

	protected:
		virtual ~View(void);
		sl::ref_ptr<sl::Camera>			m_rCamera;

		typedef std::vector<Slave>		Slaves;
		Slaves							m_sSlaves;


		sl::ref_ptr<sl::FrameStamp>		m_rFrameStamp;

	};

	typedef ref_ptr<View>			ViewPtr;
}

#endif

